package com.sixth.util;

import com.sixth.bean.MarketAdmin;
import com.sixth.bean.MarketUser;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.Subject;
import org.yaml.snakeyaml.error.Mark;

/**
 * @ClassName MarketInfoUtil
 * @Description 从subject中获得当前管理员用户的信息
 * @Author XiaoWJ
 * @Date 2022/9/9 19:58
 **/
public class MarketInfoUtil {

    public static MarketAdmin getMarketAdmin(){
        Subject subject = SecurityUtils.getSubject();
        PrincipalCollection principals = subject.getPrincipals();

        // 判断principals是否为空，若为空，则说明认证未通过或session过期，返回null
        if(principals == null) {
            return null;
        }
        return (MarketAdmin) principals.getPrimaryPrincipal();
    }


    public static MarketUser getMarketUser(){
        Subject subject = SecurityUtils.getSubject();
        PrincipalCollection principals = subject.getPrincipals();

        // 判断principals是否为空，若为空，则说明认证未通过或session过期，返回null
        if(principals == null) {
            return null;
        }
        return (MarketUser) principals.getPrimaryPrincipal();

    }


}
